///////////////////////////////////////////////////
// Election Administration Polarization
// Main RD Plot
///////////////////////////////////////////////////

* Set the working directory path
gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"

* Load the plotting command
cap prog drop rdbinscatter
do "$path/code/project_commands/rdbinscatter.ado"

* Bring in the main analysis file
use "$path/analysis_data/rd_election_analysis_data.dta", clear
keep if office=="pres"

* Select the bandwidth
rdbwselect r_oos_state_year_vs_dem rv, vce(cluster election_id)

* Make the main RD plot
rdbinscatter r_oos_state_year_vs_dem vs_dem_leo if abs(rv)<e(h_mserd), ///
	cutpoint(.5) binsize(25) func("lfitci") raw_data(1) ///
	xname("Dem Elec Official Vote Share") ///
	yname("Residual Dem Pres Vote Share (t + k)")
graph export "$path/output/rd_resid_dem_pres_vs.pdf", replace

